import json
import time

import requests
import re

movie_url = 'https://ts.gzdf.ltd//videos/202403/14/65f24c8bb80e40b11c2977ce/eb5abe/index.m3u8'
m3u8_url = 'https://ts.gzdf.ltd//videos/202403/14/65f24c8bb80e40b11c2977ce/eb5abe/{}'


headers = {
    "USER_AGENT" : "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36 Edg/122.0.0.0"
}

resp = requests.get(movie_url,headers= headers)
content = resp.text
pattern = r'index\d+\.ts'

matches = re.findall(pattern, content)
offset = 0
for i in matches:
    video_url = m3u8_url.format(i)
    time.sleep(0.5)
    resp = requests.get(video_url,headers=headers).content
    with open('爬取文件/movie/{}.ts'.format(offset), mode='wb') as file:
        file.write(resp)
    offset += 1
    print(f'{offset}写入成功')
print('写入完成')


